package mathive.client.panels;

import mathive.client.PanelHandler;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class GamesPanel {

	private VerticalPanel mainPanel = new VerticalPanel();
	private Grid mainGrid = new Grid(2, 3);
	private SudokuPanel sudokuPanel = new SudokuPanel();
	private MinemapPanel minemapPanel = new MinemapPanel();
	private ArithmeticsPanel arithmeticsPanel = new ArithmeticsPanel();
	private HTML title = new HTML("<h1>Games</h1>");
	private Image sudokuButton = new Image();
	private Image minemapButton = new Image();
	private Image arithmeticsButton = new Image();
	private Button homeButton = new Button();
	
	public GamesPanel(){

		sudokuButton.setUrlAndVisibleRect("sudokuLogo.jpg", 0, 0, 100, 100);
		minemapButton.setUrlAndVisibleRect("minemapLogo.png", 0, 0, 100, 100);
		arithmeticsButton.setUrlAndVisibleRect("arithmeticsLogo.png", 50, 50, 100, 100);
		sudokuButton.setStyleName("gameImage");
		minemapButton.setStyleName("gameImage");
		arithmeticsButton.setStyleName("gameImage");
		homeButton.setText("Back to Home");

		mainGrid.setCellPadding(10);
		mainGrid.setCellSpacing(10);
		mainGrid.setWidget(0, 0, sudokuButton);
		mainGrid.setHTML(1, 0, "<p>Sudoku</p>");
		mainGrid.setWidget(0, 1, minemapButton);
		mainGrid.setHTML(1, 1, "<p>Minemap</p>");
		mainGrid.setWidget(0, 2, arithmeticsButton);
		mainGrid.setHTML(1, 2, "<p>Arithmetics</p>");

		mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		// Listen for mouse events on the sudoku button.
		sudokuButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				mainPanel.clear();
				mainPanel.add(sudokuPanel.getPanel());	
//				mainPanel.add(sudokuPanel.getPanel(" 5197 28328 15 967769 835416 75423 8135768" +
//				" 29824 196 5976825134 12497 56548 31792"));				
			}
		});

		// Listen for mouse events on the minemap button.
		minemapButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				mainPanel.clear();
				mainPanel.add(minemapPanel.getPanel());				
			}
		});
		
		// Listen for mouse events on the arithmetics button.
		arithmeticsButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				mainPanel.clear();
				mainPanel.add(arithmeticsPanel.getPanel());				
			}
		});

		// Listen for mouse events on the home button.
		homeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				PanelHandler.showHome();
			}
		});
	}
	
	public Widget getPanel(){
		initialize();
		return mainPanel;
	}
	
	private void initialize(){
		
		mainPanel.clear();

		mainPanel.add(title);
		mainPanel.add(mainGrid);
//		mainPanel.add(homeButton);
		
	}
	
}
